// pages/history/history-record/history-record.js
const STORAGE_KEYS = require('../../../configs/STORAGE_KEYS');
const recordsStore = require('../../../stores/records')

Component({
  properties: {
    historyItem: {
      type: Object,
      default: [],
    }
  },

  data: {
  },

  methods: {
    handleDel() {
      wx.showModal({
        title: '提示',
        content: '确实要删除吗',
        complete: (res) => {
          if (res.confirm) {
            const gameNum = this.data.historyItem.gameNum;
            recordsStore.clearHistoryGame(gameNum)
            this.triggerEvent('del', gameNum)
          }
        }
      })
    },
    handleEdit() {
      wx.showModal({
        title: '提示',
        content: '确定编辑后，未结算的牌局会保存在牌局历史',
        complete: (res) => {
          if (res.confirm) {
            // 判断是否有当前正在进行的牌局
            if (wx.getStorageSync(STORAGE_KEYS.CURRENT_START_TIME)) {
              recordsStore.storeCurrentToHistory()
              recordsStore.clearCurrent()
            }
            recordsStore.continueGameNum(this.data.historyItem.gameNum)
            wx.navigateTo({
              url: '/pages/game/game',
            })
          }
        }
      })
    }
  }
})